﻿using System;
using System.Collections.Generic;
using BLL;
using Model;

public partial class ProductManage_ProductSNUnion : System.Web.UI.Page
{
    private PackageProduct pp;

    public ProductManage_ProductSNUnion()
    {
        pp = new PackageProduct();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextBox6.Focus();
    }

    /// <summary>
    /// 判断是否为二维码，并解析
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        string sn_2D = this.TextBox2.Text.Trim();
        if (sn_2D.Length >= 35)
        {
            this.TextBox5.Text = sn_2D.Substring(5, 13);
            this.TextBox2.Text = sn_2D.Substring(18, 12);
            this.Button2.Focus();
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string var_productSN = this.TextBox1.Text.Trim(); 
        List<string> prodcutSN_list = new List<string>();
        prodcutSN_list.Add(var_productSN);
        string var_packagePrdouctSN = this.TextBox2.Text.Trim();
        string var_SN3BK = this.TextBox5.Text.Trim();
        string var_productTypeName = this.TextBox6.Text.Trim();
        string userID = User.Identity.Name;
        string str;

        bool b = pp.ProductSNUnion(prodcutSN_list, var_packagePrdouctSN, var_SN3BK, var_productTypeName, userID, out str);
        if (b == true)
        {
            this.TextBox1.Text = "";
            this.TextBox2.Text = "";
            this.TextBox5.Text = "";       
        }
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + str + "');</script>");
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        string var_productSN = this.TextBox3.Text.Trim();
        IList<PackageProductInfo> list = new List<PackageProductInfo>();
        PackageProductInfo ppi = pp.GetPackageProductbyProductSN(var_productSN);
        if (!string.IsNullOrEmpty(ppi.ProductSN))
        {
            list.Add(ppi);
        }
        this.GridView1.DataSource = list;
        this.GridView1.DataBind();
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        string var_packagePrdouctSN = this.TextBox4.Text.Trim();
        IList<PackageProductInfo> list = new List<PackageProductInfo>();
        PackageProductInfo ppi = pp.GetPackageProductbyPackageProductSN(var_packagePrdouctSN);        
        if (!string.IsNullOrEmpty(ppi.PackageProductSN))
        {
            list.Add(ppi);
        }
        this.GridView2.DataSource = list;
        this.GridView2.DataBind();   
    }
}
